Override marshalling methods for Com objects#4
Override marshalling methods for Com objects#4nerzhulart wants to merge 2 commits intoSharpGenTools:masterfrom
Conversation
|
The general idea of this (and referenced PR in the main repo) is following: So I patched the generator in main repo that it emits TransformObjectFromUnmanaged call on every constructed SharpGen object, and this call has a flag isOutParam that allows callsite to differ these cases |
|
I've finally had some time to take a look at this PR. I think this adds a lot of complexity for minimal gain. The primary way to get access to a COM object is via an out parameter, which is already AddRef'd before you get it. In a well-designed ref-counting system, this is always the case. SharpGenTools doesn't do any extra logic on ref-counting lifetime since it's generally trying to be a thin wrapper. Additionally, the implementation of this seems to be messy with requiring the well-known-type override. Also, that override won't flow to all users, so every user of |
Sorry, didn't see your answer in time. I can say that SharpGen with this patch already works in Rider debugger (we use it for ICorDebug) since this summer and everything is Ok. I was needed to add these changes because initially when we moved to SharpGen all our COM objects became invalid too early, we even can't run simple tests. Then I've tried to add simple AddRef in all calls and we got a huge memory leak. That's why I had to debug and create this patch |
Override marshalling methods for Com objects to properly make AddRef/Release
SharpGenTools/SharpGenTools#140 should be merged first to apply this PR (also we need to update package dependency)